package com.cmcc.aregister.ui.activity;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.util.Xml;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.constant.Arguments;
import com.cmcc.aregister.cs.constant.ConfigUtilHelper;
import com.iflytek.speech.RecognizerListener;
import com.iflytek.speech.RecognizerResult;
import com.iflytek.speech.SpeechError;
import com.iflytek.speech.SpeechListener;
import com.iflytek.speech.SpeechRecognizer;
import com.iflytek.speech.SpeechUser;
import com.iflytek.speech.SynthesizerPlayer;
import com.iflytek.speech.SynthesizerPlayerListener;

/**
 * 语音挂号（新界面）
 * @author ld
 * 
 */
@SuppressWarnings("unused")
public class NewVoiceActivity extends ParentActivity implements OnClickListener {
    // ------view------
    private Button top_left_image;
    private ImageView iv_mic;// 话筒图片
    private ImageView iv_voice_hospital, iv_voice_department, iv_voice_date,
        iv_voice_time;
    private TextView tv_new_voice_title, tv_new_voice_message;

    // ------parameter------
    private boolean hasTwoTop = true;

    private String phonenumber = "";// 手机号码
    private String params = "";
    private RspBean rsp;
    // 识别Dialog
    private boolean isListening = false;// 是否在录音中
    private RecogizerResultModel resultModel;
    // private ListView exampleListView;// lv_voice_example_list
    // private VoiceExampleAdapter adapter;
    private SpeechRecognizer mRecognizer = null;
    private String appid = "appid=5028504c";
    private static final int TONE_TYPE_START = 0;
    private static final int TONE_TYPE_STOP = 1;
    private static final int TONE_TYPE_RESULT = 2;
    private static final int TONE_TYPE_ERROR = 3;
    private static final int TONE_TYPE_WAIT = 4;

    // private ImageView iv_wave_left;
    // private ImageView iv_wave_right;
    private MediaPlayer player;
    private static ProgressDialog dialog;

    private static final int STATUS_FREEING = 0;// 空闲状态
    private static final int STATUS_LINSTING_START = 1;// 录音状态：开始
    private static final int STATUS_LINSTING_END = 2;// 录音状态：结束
    private static final int STATUS_RECOGNIZING = 2;// 识别状态
    private static int status = STATUS_FREEING;
    // 语音合成对象.
    private SynthesizerPlayer tts;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init(R.layout.p_new_voice);
        mHttpManager.setCxt(getParent());
        initRecognizer();
        initTTS();
    }

    private void initTTS() {
        // 初始化合成对象.
        tts = SynthesizerPlayer.createSynthesizerPlayer(this, appid);
    }

    private void initRecognizer() {
        // 初始化识别对象
        mRecognizer = SpeechRecognizer.createRecognizer(this, appid);
        // 上传数据需要先执行登陆操作
        SpeechUser.getUser().login(this, null, null, appid, loginListener);
    }

    /**
     * 合成回调监听器.
     */
    private SynthesizerPlayerListener mSynListener = new SynthesizerPlayerListener() {
        /**
         * 会话结束回调监听器.
         * @param error
         */
        @Override
        public void onEnd(SpeechError error) {
            if (error != null) {}
            else {

            }
        }

        @Override
        public void onBufferPercent(int arg0, int arg1, int arg2) {
        }

        @Override
        public void onPlayBegin() {
        }

        @Override
        public void onPlayPaused() {
        }

        @Override
        public void onPlayPercent(int arg0, int arg1, int arg2) {
        }

        @Override
        public void onPlayResumed() {
        }
    };

    @Override
    protected void setupData() {
        hasTwoTop = !getIntent().hasExtra(
            Arguments.ACTIVITY_JUMP_SCREENING_TYPE);
    }

    /**
     * 识别
     */
    private void recognizer() {
        if (tts != null) {
            tts.cancel();
        }
        if (isListening) {
            iv_mic.setImageResource(R.drawable.voice_mic_off);
            // iv_wave_left.setVisibility(View.GONE);
            // iv_wave_left.setImageDrawable(null);
            // iv_wave_right.setVisibility(View.GONE);
            // iv_wave_right.setImageDrawable(null);
            // iv_mic.setBackgroundResource(R.drawable.voice_mic_off);
            playTone(TONE_TYPE_STOP);
            isListening = false;
            mRecognizer.stopListening();
        }
        else {
            // iv_mic.setBackgroundResource(R.drawable.voice_mic_on);
            iv_mic.setImageResource(R.drawable.voice_mic_on);
            playTone(TONE_TYPE_START);

            isListening = true;
            mRecognizer.startListening(mRecoListener, "sms",
                "plain_result=1,asr_sch=1", null);
            showVoiceWave(-1);
        }
    }

    private void playTTS(String text) {
        // 合成会话.
        tts.playText(text, "tts_buffer_time=100", mSynListener);
    }

    /**
     * 识别回调监听器.
     */
    private RecognizerListener mRecoListener = new RecognizerListener() {
        /**
         * 返回语义识别结果.
         * @param results,isLast
         */
        @Override
        public void onResults(ArrayList<RecognizerResult> results,
            boolean isLast) {
            showDialog();
            String text = "";
            for (int i = 0; i < results.size(); i++) {
                RecognizerResult result = results.get(i);
                text += result.text;
            }
            Log.i("XF", text);
            parseRecogizerXML(text);
            if (dialog != null && dialog.isShowing()) {
                dialog.dismiss();
            }
            if (!isNotEmpty(resultModel.hos_name)) {
                playTone(TONE_TYPE_ERROR);
                Toast.makeText(context, "请说出需要预约的医院和科室", Toast.LENGTH_LONG)
                    .show();
                // 合成会话.
                playTTS("请说出需要预约的医院和科室");
            }
            /*
             * else if (isNotEmpty(resultModel.hos_name) &&
             * !isNotEmpty(resultModel.dep_name)) { playTone(TONE_TYPE_ERROR);
             * Toast.makeText(context, "请说出需要预约的科室", Toast.LENGTH_LONG).show();
             * playtTTS("请说出需要预约的科室"); }
             */
            else {
                playTone(TONE_TYPE_RESULT);
                request();
            }
        }

        @Override
        public void onEnd(SpeechError error) {
            isListening = false;
            if (error != null) {
                playTone(TONE_TYPE_ERROR);
            }
            iv_mic.setImageResource(R.drawable.voice_mic_off);
            // iv_wave_left.setVisibility(View.GONE);
            // iv_wave_left.setImageDrawable(null);
            // iv_wave_right.setVisibility(View.GONE);
            // iv_wave_right.setImageDrawable(null);

        }

        @Override
        public void onBeginOfSpeech() {
        }

        @Override
        public void onVolumeChanged(int volume) {
            showVoiceWave(volume);
        }

        @Override
        public void onCancel() {
            isListening = false;
        }

        @Override
        public void onEndOfSpeech() {
            playTone(TONE_TYPE_WAIT);
            isListening = false;
            iv_mic.setImageResource(R.drawable.voice_mic_off);
            // iv_wave_left.setVisibility(View.GONE);
            // iv_wave_left.setImageDrawable(null);
            // iv_wave_right.setVisibility(View.GONE);
            // iv_wave_right.setImageDrawable(null);
        }
    };

    private void showDialog() {
        dialog = new ProgressDialog(this);
        dialog.setCancelable(false);
        dialog.setTitle("");
        dialog.setMessage("正在识别，请稍候...");
        dialog.show();
    }

    /**
     * 用户登录回调监听器.
     */
    private SpeechListener loginListener = new SpeechListener() {

        @Override
        public void onData(byte[] arg0) {
        }

        @Override
        public void onEnd(SpeechError error) {
            if (error != null) {}
        }

        @Override
        public void onEvent(int arg0, Bundle arg1) {
        }
    };

    private int[] getVoiceWaveResourceId(int volume) {
        int resid[] = new int[2];
        if (volume == 0) {
            resid[0] = R.drawable.voice_wave0;
            resid[1] = R.drawable.voice_wave0_r;
        }
        else if (volume > 0 && volume <= 2) {
            resid[0] = R.drawable.voice_wave1;
            resid[1] = R.drawable.voice_wave1_r;
        }
        else if (volume > 2 && volume <= 4) {
            resid[0] = R.drawable.voice_wave2;
            resid[1] = R.drawable.voice_wave2_r;
        }
        else if (volume > 4 && volume <= 6) {
            resid[0] = R.drawable.voice_wave3;
            resid[1] = R.drawable.voice_wave3_r;
        }
        else if (volume > 6 && volume <= 8) {
            resid[0] = R.drawable.voice_wave4;
            resid[1] = R.drawable.voice_wave4_r;
        }
        else if (volume > 8 && volume <= 10) {
            resid[0] = R.drawable.voice_wave5;
            resid[1] = R.drawable.voice_wave5_r;
        }
        else if (volume > 10 && volume <= 12) {
            resid[0] = R.drawable.voice_wave6;
            resid[1] = R.drawable.voice_wave6_r;
        }
        else if (volume > 12 && volume <= 14) {
            resid[0] = R.drawable.voice_wave7;
            resid[1] = R.drawable.voice_wave7_r;
        }
        else if (volume > 14 && volume <= 16) {
            resid[0] = R.drawable.voice_wave8;
            resid[1] = R.drawable.voice_wave8_r;
        }
        else if (volume > 16 && volume <= 18) {
            resid[0] = R.drawable.voice_wave9;
            resid[1] = R.drawable.voice_wave9_r;
        }
        else if (volume > 18 && volume <= 20) {
            resid[0] = R.drawable.voice_wave10;
            resid[1] = R.drawable.voice_wave10_r;
        }
        else if (volume > 20 && volume <= 22) {
            resid[0] = R.drawable.voice_wave11;
            resid[1] = R.drawable.voice_wave11_r;
        }
        else if (volume > 22 && volume <= 24) {
            resid[0] = R.drawable.voice_wave12;
            resid[1] = R.drawable.voice_wave12_r;
        }
        else if (volume > 24 && volume <= 26) {
            resid[0] = R.drawable.voice_wave13;
            resid[1] = R.drawable.voice_wave13_r;
        }
        else {
            resid[0] = R.drawable.voice_wave14;
            resid[1] = R.drawable.voice_wave14_r;
        }
        return resid;
    }

    @Override
    protected void onDestroy() {
        if (mRecognizer != null) {
            mRecognizer.destory();
        }
        if (tts != null) {
            tts.destory();
        }
        super.onDestroy();
    }

    private void showVoiceWave(int volume) {
        if (volume < 0) {
            return;
        }
        else {
            // iv_wave_left.setVisibility(View.VISIBLE);
            // iv_wave_right.setVisibility(View.VISIBLE);
        }
        int[] resid = getVoiceWaveResourceId(volume);
        if (resid.length == 2) {
            // // 设置左边声纹
            // iv_wave_left.setImageResource(resid[0]);
            // // 设置右边声纹
            // iv_wave_right.setImageResource(resid[1]);

        }

    }

    private Bitmap getRotateBitmap(int resid) {
        Bitmap bitmap = null;
        try {
            Bitmap img = BitmapFactory.decodeResource(getResources(), resid);
            Matrix matrix = new Matrix();
            matrix.postRotate(180); // 旋转180度
            bitmap = Bitmap.createBitmap(img, 0, 0, img.getWidth(),
                img.getHeight(), matrix, true);
        }
        catch (Exception e) {}
        return bitmap;
    }

    @SuppressWarnings({ "static-access" })
    private void playTone(int type) {
        if (player != null) {
            player.stop();
        }
        switch (type) {
        case TONE_TYPE_START:
            player = new MediaPlayer().create(this, R.raw.tone_start);
            break;
        case TONE_TYPE_STOP:
            player = new MediaPlayer().create(this, R.raw.tone_stop);
            break;
        case TONE_TYPE_ERROR:
            player = new MediaPlayer().create(this, R.raw.tone_error);
            break;
        case TONE_TYPE_RESULT:
            player = new MediaPlayer().create(this, R.raw.tone_result);
            break;
        case TONE_TYPE_WAIT:
            player = new MediaPlayer().create(this, R.raw.tone_wait);
            break;
        }
        if (player != null) {
            player.start();
        }
    }

    private RecogizerResultModel parseRecogizerXML(String xml) {
        resultModel = new RecogizerResultModel();
        XmlPullParser parser = Xml.newPullParser();
        try {
            InputStream is = new ByteArrayInputStream(xml.getBytes());
            parser.setInput(is, "UTF-8");
            int eventType = parser.getEventType();
            while (eventType != XmlPullParser.END_DOCUMENT) {
                if (eventType == XmlPullParser.START_TAG) {
                    if (parser.getName().equals("date")) {
                        eventType = parser.next();
                        if (!isNotEmpty(resultModel.date)) {
                            resultModel.date = parser.getText();
                        }
                    }
                    else if (parser.getName().equals("date_orig")) {
                        eventType = parser.next();
                        resultModel.dateStr = parser.getText();
                    }
                    else if (parser.getName().equals("time")) {
                        eventType = parser.next();
                        if (!isNotEmpty(resultModel.timeStart)) {
                            resultModel.timeStart = parser.getText();
                        }
                        else {
                            resultModel.timeEnd = parser.getText();
                        }
                    }
                    else if (parser.getName().equals("time_orig")) {
                        eventType = parser.next();
                        resultModel.timeStr = parser.getText();
                    }
                    else if (parser.getName().equals("hospital")) {
                        eventType = parser.next();
                        resultModel.hos_name = parser.getText();
                    }
                    else if (parser.getName().equals("hospitaloffice")) {
                        eventType = parser.next();
                        resultModel.dep_name = parser.getText();
                    }
                }
                eventType = parser.next();
            }

        }
        catch (Exception e) {}
        return resultModel;
    }

    @Override
    protected void setupView() {
        // exampleListView = (ListView)
        // findViewById(R.id.lv_voice_example_list);
        ((ImageView) findViewById(R.id.title))
            .setBackgroundResource(R.drawable.new_voice_title);

        iv_mic = (ImageView) findViewById(R.id.iv_voice_mic);
        iv_mic.setOnClickListener(onClickListener);

        top_left_image = (Button) findViewById(R.id.top_left_image);
        if (hasTwoTop) {
            top_left_image.setVisibility(View.VISIBLE);
            top_left_image.setOnClickListener(onClickListener);
        }

        // adapter = new VoiceExampleAdapter(this,
        // VoiceExampleModel.initData());
        // exampleListView.setAdapter(adapter);
        // exampleListView.setOnItemClickListener(onItemClickListener);

        // iv_wave_left = (ImageView) findViewById(R.id.iv_wave_left);
        // iv_wave_right = (ImageView) findViewById(R.id.iv_wave_right);
        iv_voice_hospital = (ImageView) findViewById(R.id.iv_voice_hospital);
        iv_voice_hospital.setOnClickListener(this);
        iv_voice_department = (ImageView) findViewById(R.id.iv_voice_department);
        iv_voice_department.setOnClickListener(this);
        iv_voice_date = (ImageView) findViewById(R.id.iv_voice_date);
        iv_voice_date.setOnClickListener(this);
        iv_voice_time = (ImageView) findViewById(R.id.iv_voice_time);
        iv_voice_time.setOnClickListener(this);
        //
        tv_new_voice_title = (TextView) findViewById(R.id.tv_new_voice_title);
        tv_new_voice_title.setText("预约医院");
        tv_new_voice_message = (TextView) findViewById(R.id.tv_new_voice_message);
        tv_new_voice_message.setText("“我要预约北大医院”");
    }

    // OnItemClickListener onItemClickListener = new OnItemClickListener() {
    //
    // @Override
    // public void onItemClick(AdapterView<?> arg0, View view, int position,
    // long arg3) {
    // adapter.showOtherExample(view, position);
    // exampleListView.setSelection(position);
    // }
    //
    // };

    OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            int id = v.getId();
            switch (id) {
            case R.id.top_left_image:
                Intent intent = new Intent(NewVoiceActivity.this,
                    NewIndexActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish();
                break;
            case R.id.iv_voice_mic:
                recognizer();
                break;
            }
        }
    };

    public boolean isNotEmpty(String str) {
        boolean isNotEmpty = false;
        if (null != str && !"".equals(str) && str.length() != 0) {
            isNotEmpty = true;
        }
        return isNotEmpty;
    }

    /*
     * <order> <MOBILE>18319044840</MOBILE> <UNIT_NAME>北大医院</UNIT_NAME>
     * <DEP_NAME>眼科</DEP_NAME> <DOCTOR_NAME></DOCTOR_NAME> <TO_DATE></TO_DATE>
     * <BEGIN_TIME></BEGIN_TIME> <END_TIME></END_TIME > </order>
     */
    private String getMessage() {
        StringBuilder sb = new StringBuilder("<order>");
        sb.append("<MOBILE>").append(phonenumber).append("</MOBILE>");
        sb.append("<UNIT_NAME>").append(resultModel.hos_name)
            .append("</UNIT_NAME>");
        sb.append("<DEP_NAME>").append(resultModel.dep_name)
            .append("</DEP_NAME>");
        sb.append("<DOCTOR_NAME></DOCTOR_NAME>");
        sb.append("<TO_DATE>").append(resultModel.date).append("</TO_DATE>");
        sb.append("<BEGIN_TIME>").append(resultModel.timeStart)
            .append("</BEGIN_TIME>");
        sb.append("<END_TIME>").append(resultModel.timeEnd)
            .append("</END_TIME>");
        sb.append("</order>");
        return sb.toString();
    }

    private void request() {
        params = "c=main&a=unit&username=wap_yiliao_touch&password=yuyue_2013@admin&message=";
        String message = getMessage();
        params += message;
        Log.i("NY", params);
        showProgressDlg(getString(R.string.notice),
            getString(R.string.order_send));
    }

    private void showProgressDlg(String title, String msg) {
        final ProgressDialog loadingDlg = new ProgressDialog(this);
        loadingDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        loadingDlg.setTitle(title);
        loadingDlg.setMessage(msg);
        loadingDlg.setIcon(android.R.drawable.ic_dialog_info);
        loadingDlg.setCancelable(true);
        loadingDlg.show();
        new Thread() {
            public void run() {
                try {
                    requestRun();
                }
                catch (Exception e) {
                    loadingDlg.dismiss();
                }
                loadingDlg.dismiss();
            }
        }.start();
        loadingDlg
            .setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    doWork();
                }

            });
    }

    private void doWork() {
        if (rsp == null) {
            if (!connectedNetwork()) {
                checkInternet();
            }
            else {
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.order_failed),
                    getString(R.string.dialog_yes));
            }
            return;
        }
        else {
            if (rsp.code == 1) {// 失败
                if (isNotEmpty(rsp.msg)) {
                    playTTS(rsp.msg);
                }
                showSingleAlertDlg(getString(R.string.notice), rsp.msg,
                    getString(R.string.dialog_yes));
            }
            else {// 成功
                if (resultModel != null) {
                    if (!isNotEmpty(resultModel.dep_name)) {
                        playTTS("请在新的界面选择科室");
                    }
                    else {
                        playTTS("请在新的界面选择医生号源");
                    }
                }
                Intent intent = new Intent(this, VoiceWebviewActivity.class);
                intent.putExtra(Arguments.ACTIVITY_JUMP_VOICE_RSP_URL, rsp.url);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        }
    }

    private void checkInternet() {
        showSingleAlertDlg(getString(R.string.notice),
            getString(R.string.dialog_check_internet),
            getString(R.string.dialog_close));
    }

    private void requestRun() {
        InputStream is = httpPost();
        rsp = parseRsp(is);
        is = null;
    }

    private InputStream httpPost() {
        InputStream is = null;
        try {
            URL url = new URL(ConfigUtilHelper.voiceReqUrl);
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(
                connection.getOutputStream(), "UTF-8");
            out.write(params);
            out.flush();
            out.close();
            is = connection.getInputStream();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return is;
    }

    public RspBean parseRsp(InputStream is) {
        RspBean rsp = null;
        XmlPullParser parser = Xml.newPullParser();
        try {
            parser.setInput(is, "UTF-8");
            int eventType = parser.getEventType();
            while (eventType != XmlPullParser.END_DOCUMENT) {
                if (eventType == XmlPullParser.START_DOCUMENT) {
                    rsp = new RspBean();
                }
                else if (eventType == XmlPullParser.START_TAG) {
                    if (parser.getName().equals("code")) {
                        eventType = parser.next();
                        rsp.code = Integer.parseInt(parser.getText());
                    }
                    else if (parser.getName().equals("message")) {
                        eventType = parser.next();
                        rsp.msg = parser.getText();
                    }
                    else if (parser.getName().equals("url")) {
                        eventType = parser.next();
                        rsp.url = URLDecoder.decode(parser.getText(), "UTF-8");
                    }
                }
                eventType = parser.next();
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return rsp;
    }

    private class RspBean {
        public RspBean() {
        }

        int code;
        String msg;
        String url;

        @Override
        public String toString() {
            return "RspBean [code=" + code + ", msg=" + msg + ", url=" + url
                + "]";
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (hasTwoTop) {
            if (!ConfigUtilHelper.isLogin(app)) {
                // phonenumber.setText(R.string.login_first_info);
            }
            else {
                phonenumber = ConfigUtilHelper.getMobile(app);
            }
        }
    }

    @Override
    protected void onPause() {
        if (player != null) {
            player.stop();
        }
        /*
         * if (tts != null) { tts.cancel(); }
         */
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
        // finish();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

    class RecogizerResultModel {
        public String hos_name = "";
        public String dep_name = "";
        public String date = "";
        public String dateStr = "";
        public String timeStart = "";
        public String timeEnd = "";
        public String timeStr = "";

        @Override
        public String toString() {
            return "RecogizerResultModel [hos_name=" + hos_name + ", dep_name="
                + dep_name + ", date=" + date + ", dateStr=" + dateStr
                + ", timeStart=" + timeStart + ", timeEnd=" + timeEnd
                + ", timeStr=" + timeStr + "]";
        }

    }

    @Override
    public void onClick(View arg0) {
        switch (arg0.getId()) {
        case R.id.iv_voice_hospital:
            tv_new_voice_title.setText("预约医院");
            tv_new_voice_message.setText("“我要预约北大医院”");
            //
            iv_voice_hospital.setImageResource(R.drawable.voice_hospital_on);
            iv_voice_department
                .setImageResource(R.drawable.voice_department_off);
            iv_voice_date.setImageResource(R.drawable.voice_date_off);
            iv_voice_time.setImageResource(R.drawable.voice_time_off);
            break;
        case R.id.iv_voice_department:
            tv_new_voice_title.setText("医院+科室");
            tv_new_voice_message.setText("“我要预约眼科医院眼科专家”");
            //
            iv_voice_hospital.setImageResource(R.drawable.voice_hospital_off);
            iv_voice_department
                .setImageResource(R.drawable.voice_department_on);
            iv_voice_date.setImageResource(R.drawable.voice_date_off);
            iv_voice_time.setImageResource(R.drawable.voice_time_off);
            break;
        case R.id.iv_voice_date:
            tv_new_voice_title.setText("日期+医院+科室");
            tv_new_voice_message.setText("“明天早上沙井人民医院妇科”");
            //
            iv_voice_hospital.setImageResource(R.drawable.voice_hospital_off);
            iv_voice_department
                .setImageResource(R.drawable.voice_department_off);
            iv_voice_date.setImageResource(R.drawable.voice_date_on);
            iv_voice_time.setImageResource(R.drawable.voice_time_off);
            break;
        case R.id.iv_voice_time:
            tv_new_voice_title.setText("日期+时间+医院+科室");
            tv_new_voice_message.setText("“明天下午2点北大医院眼科”");
            //
            iv_voice_hospital.setImageResource(R.drawable.voice_hospital_off);
            iv_voice_department
                .setImageResource(R.drawable.voice_department_off);
            iv_voice_date.setImageResource(R.drawable.voice_date_off);
            iv_voice_time.setImageResource(R.drawable.voice_time_on);
            break;
        }
    }

}